﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace _111_求工序列表中最长的加工周期_LINQ扩展方法
{
    class Program
    {
        static void Main(string[] args)
        {
            //向List中添加wordItem对象
            List<WorkItem> works = new List<WorkItem>();
            works.Add(new WorkItem
            {
                ID = 1,
                Desc = "工序 A",
                StartTime = new DateTime(2018, 5, 10, 8, 32, 16),
                EndTime = new DateTime(2018, 5, 13, 14, 20, 0)
            });
            works.Add(new WorkItem
            {
                ID = 2,
                Desc = "工序 B",
                StartTime = new DateTime(2018, 5, 12, 7, 26, 15),
                EndTime = new DateTime(2018, 5, 12, 18, 24, 15)
            });
            works.Add(new WorkItem
            {
                ID = 3,
                Desc = "工序 C",
                StartTime = new DateTime(2018, 5, 17, 9, 45, 0),
                EndTime = new DateTime(2018, 5, 19, 20, 36, 4)
            });
            works.Add(new WorkItem
            {
                ID = 4,
                Desc = "工序 D",
                StartTime = new DateTime(2018, 6, 1, 11, 0, 0),
                EndTime = new DateTime(2018, 6, 4, 16, 34, 0)
            });
            works.Add(new WorkItem
            {
                ID = 5,
                Desc = "工序 E",
                StartTime = new DateTime(2018, 7, 3, 7, 49, 0),
                EndTime = new DateTime(2018, 7, 5, 18, 17, 0)
            });

            var max = works.Max(w => w.EndTime - w.StartTime);
            Console.WriteLine("最长加工周期为：{0:%d} 天 {0:%h} 时 {0:%m} 分 {0:%s} 秒", max);


     
        }
    }

    public class WorkItem
    {
        /// <summary>
        /// 工序序号
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 工序描述
        /// </summary>
        public string Desc { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartTime { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndTime { get; set; }
    }
}
